<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<script src="/xlive/script/xlv.js"></script>
</head>
<body >
        <div id="menuMain_main" xlvobject="xlv.obj.pane" >
            <div>
                 <div xlvobject="xlv.obj.webObject" 
                 	  xlvprop="{name:'menu', objectURL:'rst.menu',methodName:'list'}"
                 	  xlvmethod="{
                 	  	returnDataManage:function(clone){
                 	  		var p_xml=this.xml_properties;
                 	  		 if(this.xml_responseMethodNames()=='list'){
								var return_data_node=this.xml_selectSingleNode('list/return/data/bom',p_xml.responseXML.documentElement);
								var bom_node=this.xml_selectSingleNode('properties/bom');
								while(bom_node.firstChild)bom_node.removeChild(bom_node.firstChild);
								while(return_data_node.firstChild) bom_node.appendChild(this.xml_adoptNode(return_data_node.firstChild));
							}else if(this.xml_responseMethodNames()=='list-bom'){
								var return_data_node=this.xml_selectSingleNode('list-bom/return/data',p_xml.responseXML.documentElement);
								var bom_key=this.getValue('list-bom/key');
								var bom_parts_node=this.xml_selectSingleNode('descendant::bom[key=\''+bom_key+'\']/parts');
								while(bom_parts_node.firstChild) bom_parts_node.removeChild(bom_parts_node.firstChild);
								while(return_data_node.firstChild) bom_parts_node.appendChild(this.xml_adoptNode(return_data_node.firstChild));
								bom_parts_node.setAttribute('xlv_got','true');
							}else if(this.xml_responseMethodNames()=='set-directory'){
								var valid=this.getValue('set-directory/return/valid',p_xml.responseXML.documentElement);
								if('true'==valid){
									var pkey=this.getValue('set-directory/parent-key');
									var key=this.getValue('set-directory/return/data/bom/key',p_xml.responseXML.documentElement);
									var parts=this.xml_selectSingleNode('descendant::bom[key=\''+pkey+'\']/parts');
									var node=this.xml_selectSingleNode('bom[key=\''+key+'\']',parts);
									var set=this.getNode('set-directory');
									if(!node) {
										parts.appendChild(node=this.xml_createElement('bom'));
										xlv.util.xmlExtendNodes(node,set,'extend',true,true,true);
										xlv.util.setXmlNodeValue('key',node,key);
									}else {
										var set_parts=this.xml_selectSingleNode('parts',set);
										if(set_parts)set.removeChild(set_parts);
										xlv.util.xmlExtendNodes(node,set,'overwrite',true,true,true);
									}
									if(parts)this.resetPartsAttribute(parts);
									parts=this.xml_selectSingleNode('parts',node);
									if(parts)this.resetPartsAttribute(parts);
								}
								this.$self('returnDataManage',clone);
							}else if(this.xml_responseMethodNames()=='set-product'){
								var valid=this.getValue('set-product/return/valid',p_xml.responseXML.documentElement);
								if('true'==valid){
									var pkey=this.getValue('set-product/parent-key');
									var key=this.getValue('set-product/return/data/bom/key',p_xml.responseXML.documentElement);
									var parts=this.xml_selectSingleNode('descendant::bom[key=\''+pkey+'\']/parts');
									var node=this.xml_selectSingleNode('bom[key=\''+key+'\']',parts);
									var set=this.getNode('set-product');
									if(!node) {
										parts.appendChild(node=this.xml_createElement('bom'));
										xlv.util.xmlExtendNodes(node,set,'extend',true,true,true);
										xlv.util.setXmlNodeValue('key',node,key);
									}else {
										xlv.util.xmlExtendNodes(node,set,'overwrite',true,true,true);
									}
									this.resetPartsAttribute(parts);
								}
								this.$self('returnDataManage',clone);
							}else if(this.xml_responseMethodNames()=='remove-bom'){
								var valid=this.getValue('remove-bom/return/valid',p_xml.responseXML.documentElement);
								if('true'==valid){
									var pkey=this.getValue('remove-bom/parent-key');
									var key=this.getValue('remove-bom/key');
									var node=this.xml_selectSingleNode('descendant::bom[key=\''+pkey+'\']/parts/bom[key=\''+key+'\']');
									if(node) {
										var parts=this.xml_selectSingleNode('parent::parts',node);
										node.parentNode.removeChild(node);
										if(parts)this.resetPartsAttribute(parts);
									}
								}
								this.$self('returnDataManage',clone);
							}else{
								this.$self('returnDataManage',clone);
							}
                 	  	},
                 	  	resetPartsAttribute:function(parts){
                 	  		if(parts.getAttribute('parts')=='bom' &amp;&amp; !parts.getAttribute('xlv_got'))return;
                 	  		var prods=this.xml_selectNodes('child::bom[type=\'1\']',parts);
                 	  		var dirs=this.xml_selectNodes('child::bom[type=\'0\']',parts);
                 	  		var attr=(prods.length==0 &amp;&amp; dirs.length &gt; 0)?'dir':(prods.length &gt; 0 &amp;&amp; dirs.length==0)?'bom':(prods.length != 0 &amp;&amp; dirs.length != 0)?'mix':'empty';
                 	  		parts.setAttribute('countDir',dirs.length);
                 	  		parts.setAttribute('countBom',prods.length);
                 	  		return parts.setAttribute('parts',attr);
                 	  	},
                 	  	selectBom:function(bom){
                 	  		var got = xlv.util.getXmlNodeValue('parts/@xlv_got',bom);
            				if(!got){
            					this.setValue(xlv.util.getXmlNodeValue('key',bom),'list-bom.key');
            					this.webMethod('list-bom');
            				}
            				return (got)?true:false;
                 	  	},
                 	  	prepareSetDirectory:function(parent,bom,type){
                 	  		this.setValue((parent)?xlv.util.getXmlNodeValue('key',parent):'','set-directory.parent-key');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('key',bom):'','set-directory.key');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('id',bom):'','set-directory.id');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('name',bom):'','set-directory.name');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('icon',bom):'','set-directory.icon');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('date',bom):'','set-directory.date');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('brief-html',bom):'','set-directory.brief-html');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('desc-html',bom):'','set-directory.desc-html');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('price',bom):'0','set-directory.price');
                 	  		this.setValue(type,'set-directory.type');
                 	  	},
                 	  	prepareSetProduct:function(parent,bom,type){
                 	  		this.setValue((parent)?xlv.util.getXmlNodeValue('key',parent):'','set-product.parent-key');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('key',bom):'','set-product.key');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('id',bom):'','set-product.id');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('name',bom):'','set-product.name');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('icon',bom):'','set-product.icon');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('date',bom):'','set-product.date');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('brief-html',bom):'','set-product.brief-html');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('desc-html',bom):'','set-product.desc-html');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('price',bom):'0','set-product.price');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('list-price',bom):'0','set-product.list-price');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('options',bom):'','set-product.options');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('addons',bom):'','set-product.addons');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('qty',bom):'-1','set-product.qty');
                 	  		this.setValue((bom)?xlv.util.getXmlNodeValue('marker',bom):'0','set-product.marker');
                 	  		this.setValue(type,'set-product.type');
                 	  	}
			 		}"
                 ></div>
                 <div xlvobject="xlv.obj.webObject" 
                 	  xlvprop="{name:'options', objectURL:'rst.options',methodName:'list'}"
                 	  xlvmethod="{
                 	  	getOptions:function(){
                 	  		var options='';
                 	  		var ops = this.getNode('list.return.data.pxml.options');
                 	  		var ns=this.xml_selectNodes('child::i',ops);
                 	  		for(var i=0;i &lt; ns.length;++i){
                 	  			options+=((options=='')?'':',')+ns[i].getAttribute('name');
                 	  		}
                 	  		return options;
                 	  	},
                 	  	getOption:function(name){
                 	  		var op=this.xml_selectSingleNode('properties/list/return/data/pxml/options/i[@name=\''+name+'\']');
                 	  		return (op)?op.cloneNode(true):null;
                 	  	}
                 	  }"
                 >
                 </div>
                 <div xlvobject="xlv.obj.webObject" 
                 	  xlvprop="{name:'addons', objectURL:'rst.addons',methodName:'list'}"
                 	  xlvmethod="{
                 	  	getAddons:function(){
                 	  		var addons='';
                 	  		var ops = this.getNode('list.return.data.pxml.addons');
                 	  		var ns=this.xml_selectNodes('child::i',ops);
                 	  		for(var i=0;i &lt; ns.length;++i){
                 	  			addons+=((addons=='')?'':',')+ns[i].getAttribute('name');
                 	  		}
                 	  		return addons;
                 	  	},
                 	  	getAddon:function(name){
                 	  		var op=this.xml_selectSingleNode('properties/list/return/data/pxml/addons/i[@name=\''+name+'\']');
                 	  		return (op)?op.cloneNode(true):null;
                 	  	}
                 	  }"
                 >
                 </div>
                 <div xlvobject="xlv.obj.webObject" 
                 	  xlvprop="{name:'menu_order', objectURL:'rst.order'}"
                 	  xlvmethod="{
                 	  	initial:function(){
                 	  		this.$self('initial');
                 	  		var date=new Date().formatDate('yyyy-MM-dd HH:mm');
                 	  		this.$P.webObjectProperties={'set-order':{'date':date}};
                 	  	},
                 	  	resetNameDate:function(){
                 	  		this.xml_setNodeText(this.getNode('set-order.date'),new Date().formatDate('yyyy-MM-dd HH:mm'));
                 	  		var n=this.getNode('set-order.name');
                 	  		var org=this.xml_getNodeText(n);
                 	  		var dm=this.getDataModel('customer');
                 	  		if(dm.$V.name)this.xml_setNodeText(n,dm.$V.name);
                 	  	},
                 	  	addProd:function(prod){
                 	  		var p=this.getNode('set-order.products');
                 	  		p.appendChild(prod);
                 	  		this.calcProd(prod);
                 	  		this.countTotal();
                 	  	},
                 	  	calcProd:function(prod){
                 	  		var tnode=this.xml_selectSingleNode('subtotal',prod);
                 	  		if(!tnode)prod.appendChild(tnode=this.xml_createElement('subtotal',''));
                 	  		var snode=this.xml_selectSingleNode('optval',prod);
                 	  		if(!snode)prod.appendChild(snode=this.xml_createElement('optval',''));
                 	  		var onode=this.xml_selectSingleNode('ostr',prod);
                 	  		if(!onode)prod.appendChild(onode=this.xml_createElement('ostr',''));
                 	  		var anode=this.xml_selectSingleNode('astr',prod);
                 	  		if(!anode)prod.appendChild(anode=this.xml_createElement('astr',''));
                 	  		var ns=this.xml_selectNodes('i',prod);
                 	  		var ostr='',astr='',optval=0,subtotal=0;
                 	  		for(var i=0;i &lt; ns.length;++i){
                 	  			var sv=ns[i].getAttribute('showValue');
                 	  			var ops=(this.xml_getNodeValue(ns[i])||'');
                 	  			if(!ops) continue;
                 	  			if('true'==sv) {
                 	  				astr+=ns[i].getAttribute('name').strip()+':'+ops.strip()+'&nbsp;';
                 	  				var nts=ops.match(/\w*(\w*(\d+)\w*)\w*/img);
                 	  				if(nts)for(var n=0;n &lt; nts.length;++n) optval+=parseInt(nts[n]);
                 	  			} else ostr+=ns[i].getAttribute('name').strip()+':'+ops.strip()+'&nbsp;';
                 	  		}
                 	  		this.xml_setNodeValue(onode, ostr);
                 	  		this.xml_setNodeValue(anode, astr);
                 	  		this.xml_setNodeValue(snode, optval);
                 	  		var st=parseInt(xlv.util.getXmlNodeValue('qty',prod)||0)*parseInt(parseInt(xlv.util.getXmlNodeValue('price',prod)||0)+optval);
                 	  		this.xml_setNodeValue(tnode, st);
                 	  	},
                 	  	removeProd:function(prod){
                 	  		var ps=this.xml_selectNodes('properties/set-order/products/bom');
                 	  		for(var i=0;i &lt; ps.length;++i){
                 	  			if(ps[i]==prod){
                 	  				ps[i].parentNode.removeChild(ps[i]);
                 	  				break;
                 	  			}
                 	  		}
                 	  		this.countTotal();
                 	  	},
                 	  	removeAllProd:function(){
                 	  		var p=this.xml_selectSingleNode('properties/set-order/products');
                 	  		while(p.firstChild) p.removeChild(p.firstChild);
                 	  		this.countTotal();
                 	  	},
                 	  	countProducts:function(){
                 	  		var ns=this.xml_selectNodes('properties/set-order/products/bom');
                 	  		return (ns)?ns.length:0;
                 	  	},
                 	  	countQty:function(){
                 	  		var qty=0;
                 	  		var ns=this.xml_selectNodes('properties/set-order/products/bom/qty');
                 	  		for(var i=0;i &lt; ns.length;++i){
                 	  			qty += parseInt(this.xml_getNodeValue(ns[i]));
                 	  		}
                 	  		return qty;
                 	  	},
                 	  	countTotal:function(){
                 	  		var total=0;
                 	  		var ns=this.xml_selectNodes('properties/set-order/products/bom/subtotal');
                 	  		for(var i=0;i &lt; ns.length;++i){
                 	  			total += parseInt(this.xml_getNodeValue(ns[i]));
                 	  		}
                 	  		this.setValue(total,'properties/set-order/total');
                 	  		return total;
                 	  	}
                 	  }"
                 >
                 </div>
                 <div xlvobject="xlv.obj.webObject" 
 					  xlvprop="{name:'customer', objectURL:'rst.customer'}"
 					  xlvmethod="{
 					  	webObjectResponse:function(){
 					  		this.$self('webObjectResponse');
 					  		if('get-properties'==this.xml_responseMethodNames())return this.getCustomer();
 					  		if('get-customer'==this.xml_responseMethodNames()){
 					  			if(this.getValue('get-customer.return.customer.fid')=='' &amp;&amp; this.$V.fid){
 					  				this.setValue(this.$V.fid,'set-customer.customer.fid');
 					  				this.setValue(this.$V.name,'set-customer.customer.name');
 					  				this.setValue(new Date().formatDate(),'set-customer.customer.create-date');
 					  				this.setValue(new Date().formatDate(),'set-customer.customer.last-date');
 					  				this.webMethod('set-customer');
 					  			}
 					  		}
 					  		if('set-customer'==this.xml_responseMethodNames()){
 					  			if('true'==this.getValue('set-customer.return.valid')){
 					  				this.setValue(this.$V.fid,'get-customer.fid');
 					  				this.webMethod('get-customer');
 					  			}
 					  		}
 					  	},
 					  	copyGetToSet:function(){
 					  		var cs=this.xml_selectNodes('child::*',this.getNode('get-customer.return.customer'));
 					  		var set=this.getNode('set-customer.customer');
 					  		while(set.firstChild) set.removeChild(set.firstChild);
 					  		for(var i=0; i&lt; cs.length;++i){
 					  			if(cs[i].nodeName=='orders') continue;
 					  			set.appendChild(cs[i].cloneNode(true));
 					  		}
 					  	},
 					  	getCustomer:function(){
 					  		var sess=FB.getSession();
 					  		if(sess) {
 					  			this.setValue(sess.uid,'get-customer.fid');
 					  			this.$V.fid=sess.uid;
 					  			FB.api({method: 'fql.query',query:'SELECT name FROM user WHERE uid='+sess.uid},
 					  					function(response){this.$V.name=response[0].name;this.webMethod('get-customer');}.bind(this));
 					  		}
 					  	}
 					  }"
                  >
                 </div>
                 <!-- 
                 <div xlvobject="xlv.obj.tree" xlvprop="{dmName:'menu_order'}"
                 ></div>
                 -->
                 <!-- 
                 <div xlvobject="xlv.obj.tree" xlvprop="{dmName:'menu'}"
                 ></div>
                 -->
                 <!--
                <div xlvobject="xlv.obj.tree" xlvprop="{dmName:'options'}"
                 ></div>
                 -->
                 <!-- 
                <div xlvobject="xlv.obj.tree" xlvprop="{dmName:'customer'}"
                 ></div>
                 -->
                 <!-- 
                 <div xlvobject="xlv.obj.googleApi" xlvprop="{packages:'map',api:'maps?sensor=true',version:'3'}"
                      xlvmethod="{
                      	mvc_modelToView:function(dm){
                      		alert('HI');
                      	}
                      }"
                 >
                 </div>
                 -->
                 <!-- 
                 <div xlvobject="xlv.obj.process" xlvprop="{title:'set-bom'}"
            	 	xlvmethod="{
            	 		process:function(){
            	 			var dm = this.getDataModel('menu');
            	 			dm.webMethod('set-bom');
            	 		}
            	 	}"
            	></div>
                 <div xlvobject="xlv.obj.process" xlvprop="{title:'list-bom'}"
            	 	xlvmethod="{
            	 		process:function(){
            	 			var dm = this.getDataModel('menu');
            	 			dm.webMethod('list-bom');
            	 		}
            	 	}"
            	></div>
            	-->
            </div>
            <div xlvobject="xlv.obj.ajaxPane" xlvprop="{paneIn:'top', paneURL:'/xlive/menu.html'}">
            </div>
             <div style="clear:both;"></div>
        </div>
</body>
</html>
